package com.xunshibao.tutor.search;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value="/search/*")
public class SearchController {
	@Autowired
	private SearchServiceImpl searcher;
	
	@RequestMapping(value="tutor")
	public String searchTutor(Criteria criteria) {
		return "search/tutor";
	}
	
	@RequestMapping(value="tutor", method=RequestMethod.POST)
	public @ResponseBody List<TutorInfoSearchItem> doSearch(HttpServletRequest request) {
		Map<String, String> keys = new HashMap<String, String>();
		Enumeration<String> enums = request.getParameterNames();
		String key ; 
		while(enums.hasMoreElements()) {
			key = enums.nextElement();
			keys.put(key, request.getParameter(key));
		}
		List<TutorInfoSearchItem> items = searcher.searchTutorInfo(keys);
		return items;
	}
}
